function showView(permissions) {
  // #ifdef APP-PLUS
  const permissionTipsArr = '_permissionTipsArr_'
  const permissionTips = Array.isArray(permissionTipsArr)
    ? permissionTipsArr.reduce((accumulator, { keyName, title, content }) => {
        accumulator[keyName] = `<div class="permission_content">
            <div class='tips-item'>
                <div class='title'>${title}</div>
                <div class='center'>${content}</div>
                </div>
            </div>`
        return accumulator
      }, {})
    : {}
  let permissionInfo = ''
  permissions.map((key) => {
    if (permissionTips[key]) {
      permissionInfo += permissionTips[key]
    } else {
      console.log(key + '未配置提示语')
    }
  })
  if (!permissionInfo) return null
  const systemInfo = uni.getSystemInfoSync()
  let wvPath = '/static/permissionTips.html'
  let wv = new plus.webview.create(
    wvPath,
    'permissionTips',
    {
      'uni-app': 'none',
      top: systemInfo.statusBarHeight,
      left: 0,
      width: systemInfo.screenWidth,
      height: systemInfo.screenHeight - systemInfo.statusBarHeight,
      background: 'transparent',
    },
    {
      permissionInfo,
    }
  )
  wv.show()
  return wv
  // #endif
  return null
}
let platform = uni.getSystemInfoSync().platform
export function permissionListener() {
  // showView(["android.permission.CAMERA", "android.permission.ACCESS_COARSE_LOCATION", "android.permission.READ_PHONE_STATE", "android.permission.READ_EXTERNAL_STORAGE"])
  if (platform !== 'android') return
  let view = null
  let createRequestPermissionListener = uni.createRequestPermissionListener()
  createRequestPermissionListener.onRequest((e) => {
    console.log('onRequest', e)
  })
  createRequestPermissionListener.onConfirm((e) => {
    console.log('onConfirm', e)
    if (view && view.close) view.close()
    if (view && view.destroy) view.destroy()
    view = showView(e)
  })
  createRequestPermissionListener.onComplete((e) => {
    if (view && view.close) view.close()
    if (view && view.destroy) view.destroy()
    view = null
    console.log('onComplete', e)
  })
}
